package com.shop.exception;

/**
 * 业务异常基类，所以业务异常必须继承于此异常
 */
public class BasisException extends RuntimeException {

    /**
     * 异常信息
     */
    protected String msg;

    /**
     * 异常码
     */
    protected int code;

    public BasisException(int code,String msgFormat,Object... args){
        super(String.format(msgFormat,args));
        this.code=code;
        this.msg=String.format(msgFormat,args);
    }

    public BasisException(){
        super();
    }

    public BasisException(String message,Throwable cause){
        super(message,cause);
    }

    public BasisException(Throwable cause){
        super(cause);
    }

    public BasisException(String message){
        super(message);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    /**
     * 实例化异常
     */
    public BasisException newInstance(String msgFormat,Object... args){
        return new BasisException(this.code,msgFormat,args);
    }
}
